class TreeNode(object):
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class Solution(object):
    def binaryTreePaths(self, root):
        """
        :type root: TreeNode
        :rtype: List[str]
        """
        out = []

        def search(s, node):
            if node == root:
                next_s = str(node.val)
            else:
                next_s = s + '->' + str(node.val)
            if not node.left and not node.right:
                out.append(next_s)
            else:
                if node.left:
                    search(next_s, node.left)
                if node.right:
                    search(next_s, node.right)

        search('', root)

        return out